﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Crystal.Common.Model
Imports System.Data.SqlClient
Imports Crystal.CLL

Public Class AddEditClient

#Region "Declare"
    Public cClientID As Integer = 0
    Public cClientName As String
    Public cListing As String
    Public cSectorID As Integer = -1
    Public cIndustryID As Integer = -1
    Public cMarketCap As Double
    Public cCapGroup As String
    Public cPrimaryExchangeID As Integer = -1
    Public cStreet1 As String
    Public cStreet2 As String
    Public cCityId As Integer = -1
    Public cStateId As Integer = -1
    Public cCountryId As Integer = -1
    Public cPostalCode As String
    Public cRegion As String
    Public cMobile As String
    Public cTelephone As String
    Public cExt As String
    Public cFax As String
    Public cEmail As String
    Public cNotes As String
    Public cCreatedBy As Integer
    Public cModifiedBy As Integer
    Public Shared strConfiguration As String = CommonCLL.mstrConnectionstring
    Public Shared selectedValue As Integer = CommonCLL.m_strSelectIDValue
#End Region

#Region "Properties"
    Public Property ClientID() As Integer
        Get
            Return cClientID
        End Get
        Set(ByVal value As Integer)
            cClientID = value
        End Set
    End Property
    Public Property ClientName() As String
        Get
            Return cClientName
        End Get
        Set(ByVal value As String)
            cClientName = value
        End Set
    End Property
    Public Property Listing() As String
        Get
            Return cListing
        End Get
        Set(ByVal value As String)
            cListing = value
        End Set
    End Property
    Public Property SectorID() As Integer
        Get
            Return cSectorID
        End Get
        Set(ByVal value As Integer)
            cSectorID = value
        End Set
    End Property
    Public Property IndustryID() As Integer
        Get
            Return cIndustryID
        End Get
        Set(ByVal value As Integer)
            cIndustryID = value
        End Set
    End Property
    Public Property MarketCap() As Double
        Get
            Return cMarketCap
        End Get
        Set(ByVal value As Double)
            cMarketCap = value
        End Set
    End Property
    Public Property CapGroup() As String
        Get
            Return cCapGroup
        End Get
        Set(ByVal value As String)
            cCapGroup = value
        End Set
    End Property
    Public Property PrimaryExchangeID() As Integer
        Get
            Return cPrimaryExchangeID
        End Get
        Set(ByVal value As Integer)
            cPrimaryExchangeID = value
        End Set
    End Property
    Public Property Street1() As String
        Get
            Return cStreet1
        End Get
        Set(ByVal value As String)
            cStreet1 = value
        End Set
    End Property
    Public Property Street2() As String
        Get
            Return cStreet2
        End Get
        Set(ByVal value As String)
            cStreet2 = value
        End Set
    End Property
    Public Property CityId() As Integer
        Get
            Return cCityId
        End Get
        Set(ByVal value As Integer)
            cCityId = value
        End Set
    End Property
    Public Property StateId() As Integer
        Get
            Return cStateId
        End Get
        Set(ByVal value As Integer)
            cStateId = value
        End Set
    End Property
    Public Property CountryId() As Integer
        Get
            Return cCountryId
        End Get
        Set(ByVal value As Integer)
            cCountryId = value
        End Set
    End Property
    Public Property PostalCode() As String
        Get
            Return cPostalCode
        End Get
        Set(ByVal value As String)
            cPostalCode = value
        End Set
    End Property
    Public Property Region() As String
        Get
            Return cRegion
        End Get
        Set(ByVal value As String)
            cRegion = value
        End Set
    End Property
    Public Property Mobile() As String
        Get
            Return cMobile
        End Get
        Set(ByVal value As String)
            cMobile = value
        End Set
    End Property
    Public Property Telephone() As String
        Get
            Return cTelephone
        End Get
        Set(ByVal value As String)
            cTelephone = value
        End Set
    End Property
    Public Property Ext() As String
        Get
            Return cExt
        End Get
        Set(ByVal value As String)
            cExt = value
        End Set
    End Property
    Public Property Fax() As String
        Get
            Return cFax
        End Get
        Set(ByVal value As String)
            cFax = value
        End Set
    End Property
    Public Property Email() As String
        Get
            Return cEmail
        End Get
        Set(ByVal value As String)
            cEmail = value
        End Set
    End Property
    Public Property Notes() As String
        Get
            Return cNotes
        End Get
        Set(ByVal value As String)
            cNotes = value
        End Set
    End Property
    Public Property CreatedBy() As Integer
        Get
            Return cCreatedBy
        End Get
        Set(ByVal value As Integer)
            cCreatedBy = value
        End Set
    End Property
    Public Property ModifiedBy() As Integer
        Get
            Return cModifiedBy
        End Get
        Set(ByVal value As Integer)
            cModifiedBy = value
        End Set
    End Property
#End Region
#Region "Enum"
    Public Enum ClientAdditionalDetail
        Sector = 0
        Industry = 1
        Exchange = 2
        Country = 3
    End Enum
    Public Enum CityStateTable
        City = 0
        State = 1
        Region = 2
    End Enum

    Public Enum ClientDetail
        Client = 0
        Listing = 1
    End Enum
#End Region
#Region "Database Methods"
    Public Shared Function GetListingData() As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_GetListingData", CommandType.StoredProcedure, ReturnTypes.DataSet)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetClientData() As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_GetClientData", CommandType.StoredProcedure, ReturnTypes.DataSet)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetClientAdditionalDetail() As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_GetClientsDetail", CommandType.StoredProcedure, ReturnTypes.DataSet)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetCityStateRegion(ByVal countryID As Integer) As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@CountryID", countryID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_GetCityStateDetail", CommandType.StoredProcedure, ReturnTypes.DataSet, param)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetTopListing(ByVal ListingID As Integer) As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@ListingID", ListingID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_GetTopListing", CommandType.StoredProcedure, ReturnTypes.DataSet, param)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function

    Public Shared Function IsClientNameExist(ByVal clientName As String, ByVal ClientID As Integer) As Boolean
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(1) As SqlParameter
        param(0) = New SqlParameter("@clientName", clientName)
        param(1) = New SqlParameter("@ClientID", ClientID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_IsClientNameExist", CommandType.StoredProcedure, ReturnTypes.Scalar, param)
        Return CType(eReturnVal.ResultObject, Boolean)
    End Function
    Public Function InsertClient() As Integer
        Dim Logmessage As New System.Text.StringBuilder
        Try
            Dim eReturnVal As ExecutionResult = Nothing
            Dim param(21) As SqlParameter
            param(0) = New SqlParameter("@ClientID", ClientID)
            param(1) = New SqlParameter("@ClientName", ClientName)
            param(2) = New SqlParameter("@Listing", Listing)
            param(3) = New SqlParameter("@SectorID", SectorID)
            param(4) = New SqlParameter("@IndustryID", IndustryID)
            param(5) = New SqlParameter("@MarketCap", MarketCap)
            param(6) = New SqlParameter("@CapGroup", CapGroup)
            param(7) = New SqlParameter("@PrimaryExchangeID", PrimaryExchangeID)
            param(8) = New SqlParameter("@Street1", Street1)
            param(9) = New SqlParameter("@Street2", Street2)
            If CityId = 0 Then
                param(10) = New SqlParameter("@CityId", DBNull.Value)
            Else
                param(10) = New SqlParameter("@CityId", CityId)
            End If
            If StateId = 0 Then
                param(11) = New SqlParameter("@StateId", DBNull.Value)
            Else
                param(11) = New SqlParameter("@StateId", StateId)
            End If
            param(12) = New SqlParameter("@CountryId", CountryId)
            param(13) = New SqlParameter("@PostalCode", PostalCode)
            param(14) = New SqlParameter("@Mobile", Mobile)
            param(15) = New SqlParameter("@Telephone", Telephone)
            param(16) = New SqlParameter("@Ext", Ext)
            param(17) = New SqlParameter("@Fax", Fax)
            param(18) = New SqlParameter("@Email", Email)
            param(19) = New SqlParameter("@Notes", Notes)
            param(20) = New SqlParameter("@CreatedBy", CreatedBy)
            param(21) = New SqlParameter("@ModifiedBy", ModifiedBy)
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_InsertClient", CommandType.StoredProcedure, ReturnTypes.Scalar, param)
            Return CType(eReturnVal.ResultObject, Integer)
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Shared Function GetClientDetail(ByVal clientID As Integer) As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@ClientID", clientID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_GetClientDetail", CommandType.StoredProcedure, ReturnTypes.DataSet, param)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function

#End Region

End Class
